<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:wh="http://java.sun.com/jsf/composite/wh"
	xmlns:p="http://primefaces.org/ui">
<h:body>
	<ui:composition template="template/template.xhtml">
		<ui:define name="content">
				<h:form id="form" styleClass="horizontal_full">
					<p:panel>
							<h1>Game Management</h1>
							<p>
								Allows you to configure, delete and create a game with different users, rounds, agent types and agents.
								After all users (amount of users) are fixed for the game please use the initialize button so market values are calculated!
							</p>
							<p:dataTable id="gameTable" var="game"
							 value="#{adminMBean.allGames()}" selectionMode="single" rowKey="#{game.name}"
							 paginatorTemplate="{RowsPerPageDropdown} {CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
	                 		 rowsPerPageTemplate="10,25,50,100" paginator="true" rows="100">
							    <f:facet name="header">
						            Game Overview
						        </f:facet>
							    
							    <p:ajax event="rowSelect" listener="#{adminMBean.eventGameRowSelect}" update=":messages" />
							    
							    <p:column headerText="Name" sortBy="#{game.name}">
							        <h:outputText value="#{game.name}" />
							    </p:column>
							 
							    <p:column headerText="Created" sortBy="#{game.startDate}">
							        <h:outputText value="#{game.formattedDate()}">
							        	<f:convertDateTime pattern="dd.MM.yyyy HH:mm" />
							        </h:outputText>
							    </p:column>
							 
							    <p:column headerText="Roundtime" sortBy="#{game.roundTime}">
							        <h:outputText value="#{game.roundTime}" />
							    </p:column>
							    
							    <p:column headerText="Number of Firms" sortBy="#{game.users.size()}">
							        <h:outputText value="#{game.users.size()}" />
							    </p:column>
							    
							    <p:column headerText="Finished" sortBy="#{game.isFinished()}">
									<p:outputPanel layout="inline" styleClass="ui-icon ui-icon-circle-check" rendered="#{game.isFinished()}" />
									<p:outputPanel layout="inline" styleClass="ui-icon ui-icon-circle-close" rendered="#{!game.isFinished()}" />
								</p:column>
							    
							    <p:column  headerText="Show Users">
						             <p:commandButton icon="ui-icon-search" title="View" action="#{adminMBean.actionShowUsers()}">
						                <f:setPropertyActionListener value="#{game}" target="#{adminMBean.selectedGame}" />
						            </p:commandButton>
						        </p:column>	
						        
						        <p:column  headerText="Show Rounds">
						             <p:commandButton icon="ui-icon-search" title="View" action="#{adminMBean.actionShowRounds()}">
						                <f:setPropertyActionListener value="#{game}" target="#{adminMBean.selectedGame}" />
						            </p:commandButton>
						        </p:column>	
						        
						        <p:column headerText="Delete Game">
										<p:commandButton icon="ui-icon-circle-minus" title="Delete" action="#{adminMBean.actionDeleteGame()}" update="gameTable">
											<f:setPropertyActionListener value="#{game}" target="#{adminMBean.selectedGame}" />
											<p:confirm header="Confirmation"
												message="Are you sure to delete the game?" icon="ui-icon-alert" />
										</p:commandButton>
										<p:confirmDialog global="true" showEffect="fade"
											hideEffect="explode">
											<p:commandButton value="Yes" type="button"
												styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
											<p:commandButton value="No" type="button"
												styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
										</p:confirmDialog>	
								</p:column>
								
								<p:column headerText="Initialize">
										<p:commandButton icon="ui-icon-refresh" title="Initialize" action="#{adminMBean.actionInitializeGame()}" update="gameTable" disabled="#{not game.initializable()}">
											<f:setPropertyActionListener value="#{game}" target="#{adminMBean.selectedGame}" />
											<p:confirm header="Confirmation"
												message="Are you sure to initialize the game?" icon="ui-icon-alert" />
										</p:commandButton>
										<p:confirmDialog global="true" showEffect="fade"
											hideEffect="explode">
											<p:commandButton value="Yes" type="button"
												styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
											<p:commandButton value="No" type="button"
												styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
										</p:confirmDialog>	
								</p:column>
								
								
								<p:column headerText="Change Name">
									<p:commandButton icon="ui-icon-gear" title="Change Name" update="gameTable" action="#{adminMBean.actionGoToUpdateGame()}">
										<f:setPropertyActionListener value="#{game}" target="#{adminMBean.selectedGame}" />
									</p:commandButton>
								</p:column>
						        			    
							    <f:facet name="footer">
							    	<p:commandButton value="Reload" action="#{adminMBean.actionRefreshAllGames()}" update="gameTable" icon="ui-icon-refresh"/>
									<p:commandButton value="Create New Game"
										action="#{adminMBean.actionGoToCreateGame()}"
										update="gameTable" icon="ui-icon-circle-plus"/>
						        </f:facet>
							</p:dataTable>
							
							<br></br>
							
							<br></br>
							<!--  
							<h3 style="margin-top: 0">User zu Spiel hinzufügen</h3>
							<p:pickList showSourceFilter="true" showTargetFilter="true" filterMatchMode="contains" 
							id="pickList" value="#{adminMBean.usersPickList}" var="user" itemLabel="#{user.nickname}" itemValue="#{user}" />
							-->
							
						</p:panel>
					</h:form>
		</ui:define>
	</ui:composition>
</h:body>
</html>